package com.ibeeking.found.cop.b.rest.service.mq;

import com.ibeeking.found.common.entity.MqMsgEventParam;
import com.ibeeking.found.cop.api.common.param.MsgEventDepartmentParam;
import com.ibeeking.found.cop.api.common.param.MsgEventFriendsParam;
import com.ibeeking.found.cop.b.rest.service.ICopDepartmentService;
import com.ibeeking.found.cop.b.rest.service.IGroupService;
import com.ibeeking.found.cop.b.rest.service.IWxOpenService;
import com.ibeeking.nematos.log.utils.LogUtils;
import com.ibeeking.nematos.utils.data.StringUtils;
import com.ibeeking.nematos.utils.json.JsonUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
public class CopGroupMqMsgEventHandler {

    @Resource
    private IGroupService groupServiceImpl;

    public boolean addGroupMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> addGroupMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取创建部门参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String chatId = friendsParam.getChatId();
            return true;
        } catch (Exception e) {
            LogUtils.error("同步部门信息任务处理异常:{}", e);
            return false;
        }
    }

    public boolean updateGroupMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> updateDepartmentMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取创建部门参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String chatId = friendsParam.getChatId();
            String detailOperType = friendsParam.getUpdateDetail();
            String joinScene = friendsParam.getJoinScene();
            String quitScene = friendsParam.getQuitScene();
            String memChangeCnt = friendsParam.getMemChangeCnt();
            return true;
        } catch (Exception e) {
            LogUtils.error("同步部门信息任务处理异常:{}", e);
            return false;
        }
    }

    public boolean dismissGroupMsgEvent(MqMsgEventParam mqParam, Map<String, Object> extMap) {
        try {
            LogUtils.info(">>>>>>> deleteDepartmentMsgEvent:{}", JsonUtils.toJsonStr(mqParam));
            String tenantId = mqParam.getTenantId();
            //同步部门列表
            String paramStr = mqParam.getParams();
            if(StringUtils.isEmpty(paramStr)) {
                LogUtils.error("从MQ读取创建部门参数是空的！");
                return false;
            }
            MsgEventFriendsParam friendsParam = JsonUtils.fromJson(paramStr, MsgEventFriendsParam.class);
            String chatId = friendsParam.getChatId();

            return true;
        } catch (Exception e) {
            LogUtils.error("同步部门信息任务处理异常:{}", e);
            return false;
        }
    }

}

